<script setup lang="ts">
import { useAssistStore } from '@/store/modules/Assist/useAssistStore';
import { reactive } from 'vue';
import { storeToRefs } from 'pinia';
import type { CSSProperties } from 'vue';
import { url } from '@/utils/mappingUrl';

interface Mark {
  style: CSSProperties;
  label: string;
}

type Marks = Record<number, Mark | string>;

// Store 相关
const { warningInfo, sliderValue, resourceData } = storeToRefs(useAssistStore());
const { sliderChange } = useAssistStore();
// 滑块标记
const marks = reactive<Marks>({
  500: {
    style: { color: '#00ffff' },
    label: '500m'
  },
  1000: {
    style: { color: '#00ffff' },
    label: '1km'
  },
  2000: {
    style: { color: '#00ffff' },
    label: '2km'
  },
  3000: {
    style: { color: '#00ffff' },
    label: '3km'
  },
  5000: {
    style: { color: '#00ffff' },
    label: '5km'
  }
});
</script>

<template>
  <div class="surrounding-resources">
    <!-- 经纬度显示 -->
    <div class="surrounding-resources__coordinates">
      <div class="coordinates__item">
        <span class="coordinates__label">经度</span>
        <span class="coordinates__value">
          {{ warningInfo.longitude || '暂无' }}
        </span>
      </div>
      <div class="coordinates__item">
        <span class="coordinates__label">纬度</span>
        <span class="coordinates__value">
          {{ warningInfo.latitude || '暂无' }}
        </span>
      </div>
    </div>

    <!-- 半径滑块 -->
    <div class="surrounding-resources__radius-control">
      <span class="radius-control__label">区间半径</span>
      <el-slider v-model="sliderValue" :step="500" :min="500" :max="5000" :marks="marks" class="radius-control__slider" @change="sliderChange" />
    </div>

    <!-- 周边资源列表 -->
    <div class="surrounding-resources__list">
      <h3 class="resources-list__title">周边资源</h3>
      <el-scrollbar class="custom-scrollbar" height="calc(100% - 10%)">
        <ul class="resources-list__container">
          <li v-for="(item, index) in resourceData" :key="index" class="resource-item">
            <img :src="url[item.label]" :alt="item.label" class="resource-item__icon" />
            <div class="resource-item__info">
              <span class="resource-item__name">{{ item.label }}</span>
              <span class="resource-item__count">{{ item.total || 0 }}个</span>
            </div>
          </li>
        </ul>
      </el-scrollbar>
    </div>
  </div>
</template>

<style scoped lang="scss">
.surrounding-resources {
  padding: 1.25rem;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background-image: url(@/assets/largescreen/blue-kuang.png);
  background-size: 100% 100%;

  &__coordinates {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 7%;
    color: white;
  }

  .coordinates__item {
    display: flex;
    width: 45%;
    justify-content: space-between;
    align-items: center;
  }

  .coordinates__value {
    width: 8.125rem;
    height: 1.875rem;
    line-height: 1.875rem;
    text-align: center;
    color: #1aecff;
    font-weight: 700;
    background-image: url('@/assets/largescreen/Latitudeandlongitude.png');
    background-size: 100% 100%;
    font-size: 0.875rem;
  }

  &__radius-control {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.625rem;
    box-sizing: border-box;
    font-size: 1rem;
    color: #fff;
    width: 100%;
    height: 2.5rem;
    margin: 20px 0;
  }

  .radius-control__slider {
    width: 70%;
    margin-left: 0.625rem;

    :deep(.el-slider__bar) {
      background-color: #1aecff;
    }

    :deep(.el-slider__runway) {
      background-color: #067898;
    }

    :deep(.el-slider__button) {
      background-color: #1aecff;
      border: none;
      box-shadow: 0 0 0.375rem 0.375rem #0d9ab6;
      width: 0.875rem;
      height: 0.875rem;
    }
  }

  &__list {
    width: 100%;
    height: 80%;
  }

  .resources-list__title {
    color: #1aecff;
    font-weight: 700;
    height: 10%;
    margin: 0;
    padding: 0;
  }

  .custom-scrollbar {
    height: 85%;
  }

  .resources-list__container {
    height: 90%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .resource-item {
    cursor: pointer;
    box-sizing: border-box;
    padding-bottom: 0.625rem;
    width: 48%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.625rem;

    &__icon {
      width: 2.0625rem;
      height: 2.0625rem;
      flex-shrink: 0;
    }

    &__info {
      width: 78%;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    &__name {
      width: 12.5rem;
      font-size: 0.75rem;
      font-weight: 500;
      color: #fff;
      text-align: left;
    }

    &__count {
      font-size: 1.125rem;
      font-family: PangMenZhengDao;
      font-weight: 400;
      color: #0ff;
      text-align: right;
      min-width: 40%;
    }
  }
}
</style>
